<?php
	// Definition des constantes et variables
	define('LOGIN','admin');
	define('PASSWORD','admin');
	$errorMessage = '';

	// Test de l'envoi du formulaire
	if(!empty($_POST))	{
		// Test transmission des identifiants
		if(!empty($_POST['login']) && !empty($_POST['password'])) {
			// Sont-ils les memes que les constantes ?
			if($_POST['login'] !== LOGIN) {
				$errorMessage = 'Mauvais login !';
			}
			elseif($_POST['password'] !== PASSWORD)	{  
				$errorMessage = 'Mauvais password !';
			}
			else {
				// On ouvre la session
				session_start();
				// On enregistre le login en session
				$_SESSION['login'] = LOGIN;
				// On redirige vers le fichier admin.php
				header('Location: home.php');
				exit();
			}
		} else {
			$errorMessage = 'Veuillez saisir vos identifiants !';
		}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Lunch At Home</title> 
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
	<meta name="description" content=""/> 
	<meta name="keywords" CONTENT=""> 
	<meta name="url" content=""> 
	<meta name="robots" content="all">		
	<link rel="icon" type="image/png" href="images/Favicon.png" /> 
	
	<link rel="stylesheet" type="text/css" media="all" href="Styles/bootstrap.css" />
	<link rel="stylesheet" type="text/css" media="all" href="Styles/style.css" />
	
	

	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
</head>

<body>
	<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
        <div class="well" id="boiteConnexion">
            <table>
            	<?php
					// Erreur ?
					if(!empty($errorMessage)) {
						echo '<tr><td colspan="2" class="center error">', htmlspecialchars($errorMessage) ,'</td></tr>';
					}
					else {
						echo '<tr><td colspan="2" class="center" style="font-weight:bold; font-size:18px; color:#404040">Lunch At Home</td></tr>';
					}						
				?>
                <tr>
                    <td><label for="login">Login : </label></td>
                    <td><input class="span5" id="login" name="login" type="text"></td>
                </tr>
                <tr>
                    <td><label for="password">Password : </label></td>
                    <td><input class="span5" id="password" name="password" type="password"></td>
                </tr>
                <tr>
                    <td colspan="2" class="center"><input class="btn" type="submit" name="submit" value="Log In"/></td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
